<template>
	<view>
		<view class="specifications" v-for="(item,index) in list" :key='index'>
			<p>{{item.name}}</p>
			<view style="display: flex;flex-wrap: wrap;">
				<view v-for="(speckItem,speckIndex) in item.value" :key="speckIndex">
					<view class='checkbox' :class="item.checked === speckItem ?  'selectBox' : 'check'" @click="labelBtn(item,speckItem)">{{speckItem}}</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		get,
		showToast
	} from '../../js/common';
	export default {
		data() {
			return {
				count: 0,
				checkId: ''
			}
		},
		props: {
			list: Array,
			goodsId: String
		},
		methods: {
			labelBtn(item, speckItem) {
				item.checked = speckItem
				this.getSpesDesc()
			},
			getSpesDesc(){
				let spesDesc = ''
				for (let i = 0; i < this.list.length; i++) {
					spesDesc += this.list[i].name + ':' + this.list[i].checked + ';'
				}
				const params = {
					goodsId: this.goodsId,
					specDesc: spesDesc
				}
				get('mobileapi/anon/goods/getProductBySpec', params).then(res => {
					let data = {
						productId: res.productBySpec.id,
						mktprice: res.productBySpec.mktprice,
						price: res.productBySpec.price
					}
					this.$emit('info',data)
				})
			}
		}
	}
</script>
<style>
	.selectBox {
		background: #EB5248 !important;
		color: #fff !important;
		border: 1px solid #FFFFFF;
	}

	.check {
		border: 1px solid #666666;
	}

	.checkbox {
		padding: 5px 10px;
		margin: 10px;
		border-radius: 7upx;
		color: #000;
		font-size: 24upx;
	}
</style>
